package abs.web.jsf;

import abs.dao.CompaniasDAO;
import abs.dao.SucursalesDAO;

import abs.domain.Companias;
import abs.domain.Sucursales;

import abs.service.SucursalesService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Component;

import org.springframework.transaction.annotation.Transactional;

/**
 * Spring Component that handles CRUD requests for Sucursales entities
 * 
 */
@Scope("session")
@Component("SucursalesComponent")
public class SucursalesComponentImpl implements SucursalesComponent {

	/**
	 * Data type variable that provides CRUD operations for Sucursales entities
	 * 
	 */
	private Sucursales sucursales;

	/**
	 * DAO injected by Spring that manages Companias entities
	 * 
	 */
	private Companias companias;

	/**
	 * DAO injected by Spring that manages Companias entities
	 * 
	 */
	@Autowired
	private CompaniasDAO companiasDAO;

	/**
	 * DAO injected by Spring that manages Sucursales entities
	 * 
	 */
	@Autowired
	private SucursalesDAO sucursalesDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for Sucursales entities
	 * 
	 */
	@Autowired
	private SucursalesService sucursalesService;

	/** 
	 */
	public SucursalesComponentImpl() {
	}

	/**
	 * Save an existing Sucursales entity
	 * 
	 */
	@Transactional
	public String saveSucursales(Sucursales sucursales) {
		sucursalesService.saveSucursales(sucursales);
		return "/jsf/sucursales/listSucursaless.xhtml";
	}

	/**
	 * View an existing Companias entity
	 * 
	 */
	@Transactional
	public String selectSucursalesCompanias(String sucursales_co001cdgo, String related_companias_co000nocia) {
		companias = companiasDAO.findCompaniasByPrimaryKey(related_companias_co000nocia, -1, -1);
		return "/jsf/sucursales/companias/viewCompanias.xhtml";
	}

	/**
	 * Select the child Companias entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeleteSucursalesCompanias(String sucursales_co001cdgo, String related_companias_co000nocia) {
		companias = companiasDAO.findCompaniasByPrimaryKey(related_companias_co000nocia);

		return "/jsf/sucursales/companias/deleteCompanias.xhtml";
	}

	/**
	 * Edit an existing Companias entity
	 * 
	 */
	@Transactional
	public String editSucursalesCompanias(String sucursales_co001cdgo, String related_companias_co000nocia) {
		companias = companiasDAO.findCompaniasByPrimaryKey(related_companias_co000nocia, -1, -1);
		return "/jsf/sucursales/companias/editCompanias.xhtml";
	}

	/**
	 * Select the Sucursales entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeleteSucursales(String co001cdgoKey) {
		sucursales = sucursalesDAO.findSucursalesByPrimaryKey(co001cdgoKey);

		return "/jsf/sucursales/deleteSucursales.xhtml";
	}

	/**
	 * Show all Sucursales entities
	 * 
	 */
	@Transactional
	public List<Sucursales> listSucursaless() {
		return new java.util.ArrayList<Sucursales>(sucursalesService.loadSucursaless());
	}

	/**
	 * Delete an existing Companias entity
	 * 
	 */
	@Transactional
	public String deleteSucursalesCompanias(String sucursales_co001cdgo, String related_companias_co000nocia) {
		sucursales = sucursalesService.deleteSucursalesCompanias(sucursales_co001cdgo, related_companias_co000nocia);

		return "/jsf/sucursales/viewSucursales.xhtml";
	}

	/**
	 * Select an existing Sucursales entity
	 * 
	 */
	@Transactional
	public String selectSucursales(String co001cdgoKey) {
		sucursales = sucursalesDAO.findSucursalesByPrimaryKey(co001cdgoKey);

		return "/jsf/sucursales/viewSucursales.xhtml";
	}

	/**
	 * Delete an existing Sucursales entity
	 * 
	 */
	@Transactional
	public String deleteSucursales(String co001cdgoKey) {
		Sucursales sucursales = sucursalesDAO.findSucursalesByPrimaryKey(co001cdgoKey);
		sucursalesService.deleteSucursales(sucursales);
		return "/jsf/sucursales/listSucursaless.xhtml";
	}

	/**
	 * Create a new Companias entity
	 * 
	 */
	@Transactional
	public String newSucursalesCompanias(String sucursales_co001cdgo) {
		companias = new Companias();

		return "/jsf/sucursales/companias/createCompanias.xhtml";
	}

	/**
	 * Save an existing Companias entity
	 * 
	 */
	@Transactional
	public String saveSucursalesCompanias(String sucursales_co001cdgo, Companias companias) {
		sucursales = sucursalesService.saveSucursalesCompanias(sucursales_co001cdgo, companias);

		return "/jsf/sucursales/viewSucursales.xhtml";
	}

	/**
	 * Create a new Sucursales entity
	 * 
	 */
	@Transactional
	public String newSucursales() {
		sucursales = new Sucursales();

		return "/jsf/sucursales/createSucursales.xhtml";
	}

	/**
	 * Getter for variable Sucursales
	 * 
	 */
	@Transactional
	public Companias getCompanias() {
		return companias;
	}

	/**
	 * Get Companias entity by Sucursales
	 * 
	 */
	@Transactional
	public Companias getSucursalesCompanias(String co001cdgoKey) {
		return sucursalesDAO.findSucursalesByPrimaryKey(co001cdgoKey).getCompanias();
	}

	/**
	 * Edit an existing Sucursales entity
	 * 
	 */
	@Transactional
	public String editSucursales(String co001cdgoKey) {
		sucursales = sucursalesDAO.findSucursalesByPrimaryKey(co001cdgoKey);

		return "/jsf/sucursales/editSucursales.xhtml";
	}

	/**
	 * Getter for variable Sucursales
	 * 
	 */
	@Transactional
	public Sucursales getSucursales() {
		return sucursales;
	}

}
